﻿using System.Configuration;
using System.Data;
using System.ServiceProcess;
using System.Windows;

namespace CBS.Desktop
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static readonly string ExcelTemplatePath = "/Resource/ExcelTempate";

        public Dictionary<string, string> ExcelTemplate = new()
        {
            { "StudentSignUpImportTemplate",$"{ExcelTemplatePath}/StudentSignUpImportTemplate"},
        };

        private void CheckAndStartMySQLService()
        {
            const string serviceName = "MySQL"; // 根据实际的服务名称修改

            using (ServiceController service = new ServiceController(serviceName))
            {
                try
                {
                    // 检查服务状态
                    if (service.Status == ServiceControllerStatus.Stopped)
                    {
                        // 如果服务已停止，则启动服务
                        service.Start();
                        service.WaitForStatus(ServiceControllerStatus.Running); // 等待服务启动
                    }

                    // 服务已启动，继续 WPF 启动流程
                    MessageBox.Show("MySQL 服务已启动，继续应用程序。");
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"无法检查或启动 MySQL 服务: {ex.Message}");
                    Application.Current.Shutdown(); // 关闭应用程序
                }
            }
        }
    }

}
